<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Glk Template</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Glk Template' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">Architecture32Kit</a></li><li><b>Glk Template</b></li></ul></div>
<p class="purpose">Glk is a fully-featured input-output model, designed by Andrew Plotkin for use with the Glulx virtual machine, but not used only for that. All 32-bit Inform programs use Glk.</p>

<ul class="toc"><li><a href="gltm.html#SP1">&#167;1. Glk definitions</a></li><li><a href="gltm.html#SP2">&#167;2. Glk/Glulx gestalts</a></li><li><a href="gltm.html#SP3">&#167;3. Glk object recovery</a></li><li><a href="gltm.html#SP5">&#167;5. Glk windows</a></li><li><a href="gltm.html#SP6">&#167;6. Glk events</a></li><li><a href="gltm.html#SP12">&#167;12. Glk character event function keycodes</a></li><li><a href="gltm.html#SP13">&#167;13. Tracking input requests</a></li><li><a href="gltm.html#SP14">&#167;14. Suspending and resuming text input</a></li><li><a href="gltm.html#SP16">&#167;16. Debugging verb</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Glk definitions.</b>General Glk constants and properties.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GLK_NULL</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="identifier-syntax">Property</span><span class="plain-syntax"> </span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Property</span><span class="plain-syntax"> </span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Property</span><span class="plain-syntax"> </span><span class="identifier-syntax">line_input_buffer_maxlen</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Property</span><span class="plain-syntax"> </span><span class="identifier-syntax">line_input_buffer_uni</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Glk/Glulx gestalts.</b>A few small definitions for handling Glk/Glulx gestalts.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="comment-syntax">Can't use gestalt_GarglkText_FAKE or GLULX_GESTALT_Double here as they don't have the correct values yet</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax"> --&gt; (24 + </span><span class="constant-syntax">7</span><span class="plain-syntax">);</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">Cached_Glulx_Gestalts</span><span class="plain-syntax"> --&gt; (13 + </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GlkFeatureTest</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GlulxFeatureTest</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Cached_Glulx_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">id</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Glk object recovery.</b><span class="extract"><span class="extract-syntax">GGRecoverObjects</span></span> handles recovering the Glk objects after restarting or restoring.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GGRecoverObjects</span><span class="plain-syntax"> </span><span class="identifier-syntax">ref</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Reset all Glk references as if none existed</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">FollowRulebook</span><span class="plain-syntax">(</span><span class="identifier-syntax">RESET_GLK_REFERENCES_RB</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Iterate through each of the windows, streams, file refs and sound channels</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_window_iterate</span><span class="plain-syntax">(</span><span class="identifier-syntax">ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ref</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">FollowRulebook</span><span class="plain-syntax">(</span><span class="identifier-syntax">IDENTIFY_WINDOWS_RB</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_stream_iterate</span><span class="plain-syntax">(</span><span class="identifier-syntax">ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ref</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">FollowRulebook</span><span class="plain-syntax">(</span><span class="identifier-syntax">IDENTIFY_STREAMS_RB</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_fileref_iterate</span><span class="plain-syntax">(</span><span class="identifier-syntax">ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ref</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">FollowRulebook</span><span class="plain-syntax">(</span><span class="identifier-syntax">IDENTIFY_FILEREFS_RB</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_Sound</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_schannel_iterate</span><span class="plain-syntax">(</span><span class="identifier-syntax">ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ref</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">FollowRulebook</span><span class="plain-syntax">(</span><span class="identifier-syntax">IDENTIFY_SCHANNELS_RB</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Tell the game to tie up any loose ends</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">FollowRulebook</span><span class="plain-syntax">(</span><span class="identifier-syntax">GLK_OBJECT_UPDATING_RB</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>The built in object recovery rules.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">RESET_GLK_REFERENCES_R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Main_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Main_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_rock</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GG_MAINWIN_ROCK</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Status_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Status_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_rock</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GG_STATUSWIN_ROCK</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Quote_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Quote_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_rock</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GG_QUOTEWIN_ROCK</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_scriptfref</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_scriptstr</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_savestr</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">statuswin_cursize</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_foregroundchan</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_backgroundchan</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">Ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">COMMAND_STREAM</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_commandstr</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gg_command_reading</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">Endif</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">CACHE_GESTALTS_R</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">: </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">gestalt_GarglkText_FAKE</span><span class="plain-syntax">: </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">ix</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_GarglkText_FAKE</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_GarglkText</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_DrawImage_BUFFER</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_DrawImage</span><span class="plain-syntax">, </span><span class="identifier-syntax">wintype_TextBuffer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_DrawImage_GRAPHICS</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_DrawImage</span><span class="plain-syntax">, </span><span class="identifier-syntax">wintype_Graphics</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_HyperlinkInput_BUFFER</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_HyperlinkInput</span><span class="plain-syntax">, </span><span class="identifier-syntax">wintype_TextBuffer</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_HyperlinkInput_GRID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_HyperlinkInput</span><span class="plain-syntax">, </span><span class="identifier-syntax">wintype_TextGrid</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_MouseInput_GRAPHICS</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_MouseInput</span><span class="plain-syntax">, </span><span class="identifier-syntax">wintype_Graphics</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_MouseInput_GRID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_MouseInput</span><span class="plain-syntax">, </span><span class="identifier-syntax">wintype_TextGrid</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">: </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">GLULX_GESTALT_Double</span><span class="plain-syntax">: </span><span class="identifier-syntax">ix</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        @</span><span class="identifier-syntax">gestalt</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Cached_Glulx_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> = </span><span class="identifier-syntax">res</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">IDENTIFY_WINDOWS_R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_MAINWIN_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Main_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_STATUSWIN_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Status_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_statuswin</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_QUOTEWIN_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Quote_Window</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_quotewin</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">IDENTIFY_STREAMS_R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_SAVESTR_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_savestr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_SCRIPTSTR_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_scriptstr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">Ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">COMMAND_STREAM</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_COMMANDWSTR_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_commandstr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_command_reading</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_COMMANDRSTR_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_commandstr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_command_reading</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">Endif</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">IDENTIFY_FILEREFS_R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_SCRIPTFREF_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_scriptfref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">IDENTIFY_SCHANNELS_R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_glk_object_rock</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_FOREGROUNDCHAN_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_foregroundchan</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">GG_BACKGROUNDCHAN_ROCK</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">gg_backgroundchan</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_glk_object_reference</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">STOP_SCHANNELS_R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_Sound</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_foregroundchan</span><span class="plain-syntax"> ~= </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_schannel_stop</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_foregroundchan</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gg_backgroundchan</span><span class="plain-syntax"> ~= </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_schannel_stop</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_backgroundchan</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Glk windows.</b>Functions for minimal Glk windows support.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax"> </span><span class="identifier-syntax">ref</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ref</span><span class="plain-syntax"> ~= </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax"> = </span><span class="identifier-syntax">K_Glk_Window_First</span><span class="plain-syntax">: </span><span class="identifier-syntax">win</span><span class="plain-syntax">: </span><span class="identifier-syntax">win</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">K_Glk_Window_Next</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax"> == </span><span class="identifier-syntax">ref</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WindowClear</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_window_clear</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WindowFocus</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_set_window</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"WindowIsClosed"</span><span class="plain-syntax">, </span><span class="string-syntax">"WindowFocus: Cannot perform this Glk window operation on a closed window."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"WindowIsNothing"</span><span class="plain-syntax">, </span><span class="string-syntax">"WindowFocus: Cannot perform this Glk window operation on nothing."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WindowGetSize</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">index</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_window_get_size</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax"> + </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">index</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WindowMoveCursor</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_window_type</span><span class="plain-syntax"> == </span><span class="identifier-syntax">wintype_TextGrid</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">col</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">glk_window_move_cursor</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"WindowBadGridCursor"</span><span class="plain-syntax">, </span><span class="string-syntax">"WindowMoveCursor: Grid window cursor row must be &gt;= 1."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"WindowIsWrongType"</span><span class="plain-syntax">, </span><span class="string-syntax">"WindowMoveCursor: Wrong window type for this Glk window operation."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"WindowIsClosed"</span><span class="plain-syntax">, </span><span class="string-syntax">"WindowMoveCursor: Cannot perform this Glk window operation on a closed window."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"WindowIsNothing"</span><span class="plain-syntax">, </span><span class="string-syntax">"WindowMoveCursor: Cannot perform this Glk window operation on nothing."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Glk events.</b>Glk events use a BV to represent the event struct, with an extra slot for a
line input text. For an original line event, the text slot actually remains
set to 0, which is understood as meaning that the underling window's buffer
is used instead.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">5</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">6</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Compare</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev1</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev2</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">d</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_left</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_right</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax"> &lt;= </span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">d</span><span class="plain-syntax"> = </span><span class="identifier-syntax">PVField</span><span class="plain-syntax">(</span><span class="identifier-syntax">ev1</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">) - </span><span class="identifier-syntax">PVField</span><span class="plain-syntax">(</span><span class="identifier-syntax">ev2</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">d</span><span class="plain-syntax"> ~= </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">d</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_left</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_right</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev2</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">text_left</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">text_right</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TEXT_TY_Compare</span><span class="plain-syntax">(</span><span class="identifier-syntax">text_left</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_right</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_left</span><span class="plain-syntax"> - </span><span class="identifier-syntax">text_right</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Copy</span><span class="plain-syntax"> </span><span class="identifier-syntax">evto</span><span class="plain-syntax"> </span><span class="identifier-syntax">evfrom</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> </span><span class="identifier-syntax">recycling</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">txtfrom</span><span class="plain-syntax"> </span><span class="identifier-syntax">txtto</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">evto</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">evfrom</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">evto</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">evfrom</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">evto</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">evfrom</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">evto</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">evfrom</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">evto</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">evfrom</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">evfrom</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">evto</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEXT_TY</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">CopyPV</span><span class="plain-syntax">(</span><span class="identifier-syntax">evto</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">, </span><span class="identifier-syntax">evfrom</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Create</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind_id</span><span class="plain-syntax"> </span><span class="identifier-syntax">sb_address</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">short_block</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">short_block</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CreatePVShortBlock</span><span class="plain-syntax">(</span><span class="identifier-syntax">sb_address</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind_id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">short_block</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">evtype_None</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">short_block</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">short_block</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">short_block</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">short_block</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">short_block</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Destroy</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax"> </span><span class="identifier-syntax">txt</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">txt</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">txt</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DestroyPV</span><span class="plain-syntax">(</span><span class="identifier-syntax">txt</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Say</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">GLK_EVENT_TYPE_TY</span><span class="plain-syntax">, </span><span class="identifier-syntax">evtype</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> == </span><span class="identifier-syntax">evtype_CharInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_MouseInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_Hyperlink</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" ("</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">evtype</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">evtype_CharInput</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_put_char_uni</span><span class="plain-syntax">(</span><span class="identifier-syntax">MapGlkKeyCodeToUnicode</span><span class="plain-syntax">(</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"~"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">TEXT_TY_Say</span><span class="plain-syntax">(</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_uni</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">glk_put_buffer_uni</span><span class="plain-syntax">(</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">glk_put_buffer</span><span class="plain-syntax">(</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"~"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">evtype_MouseInput</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_window_type</span><span class="plain-syntax"> == </span><span class="identifier-syntax">wintype_TextGrid</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">), </span><span class="string-syntax">", "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">, </span><span class="string-syntax">", "</span><span class="plain-syntax">, </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">evtype_Hyperlink</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">") in "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">the</span><span class="plain-syntax">) </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>These functions then support the Inform 7 API for creating and using Glk
event BVs.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_New</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> </span><span class="identifier-syntax">val1</span><span class="plain-syntax"> </span><span class="identifier-syntax">val2</span><span class="plain-syntax"> </span><span class="identifier-syntax">text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> == </span><span class="identifier-syntax">evtype_CharInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_MouseInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_Hyperlink</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">gg_mainwin</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Event type specific processing</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">evtype</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax">, </span><span class="identifier-syntax">evtype_Hyperlink</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (~~(</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_window_type</span><span class="plain-syntax"> == </span><span class="identifier-syntax">wintype_TextBuffer</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">wintype_TextGrid</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"EventWrongWindowType"</span><span class="plain-syntax">, </span><span class="string-syntax">"GLK_EVENT_TY_New: Glk event created for window of wrong type."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">evtype_MouseInput</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (~~(</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_window_type</span><span class="plain-syntax"> == </span><span class="identifier-syntax">wintype_Graphics</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">wintype_TextGrid</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"EventWrongWindowType"</span><span class="plain-syntax">, </span><span class="string-syntax">"GLK_EVENT_TY_New: Glk event created for window of wrong type."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="comment-syntax">Fix the coordinates of grid window mouse events</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_window_type</span><span class="plain-syntax"> == </span><span class="identifier-syntax">wintype_TextGrid</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">val1</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">val2</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val1</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax"> || </span><span class="identifier-syntax">val2</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"EventInvalidMouseCoords"</span><span class="plain-syntax">, </span><span class="string-syntax">"GLK_EVENT_TY_New: Glk mouse event created with invalid coordinates."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">evtype</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">val1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">val2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">text</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">TEXT_TY</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">CopyPV</span><span class="plain-syntax">(</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">, </span><span class="identifier-syntax">text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Type</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Window</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> == </span><span class="identifier-syntax">evtype_CharInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_MouseInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_Hyperlink</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"EventWrongType"</span><span class="plain-syntax">, </span><span class="string-syntax">"GLK_EVENT_TY_Window: Glk event phrase called for wrong event type."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Value1</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> == </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">evtype</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">evtype_CharInput</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">MapGlkKeyCodeToUnicode</span><span class="plain-syntax">(</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">evtype_MouseInput</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax">).</span><span class="identifier-syntax">glk_window_type</span><span class="plain-syntax"> == </span><span class="identifier-syntax">wintype_TextGrid</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">evtype_Hyperlink</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"EventWrongType"</span><span class="plain-syntax">, </span><span class="string-syntax">"GLK_EVENT_TY_Value1: Glk event phrase called for wrong event type."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Value2</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> == </span><span class="identifier-syntax">evtype_MouseInput</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax">).</span><span class="identifier-syntax">glk_window_type</span><span class="plain-syntax"> == </span><span class="identifier-syntax">wintype_TextGrid</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"EventWrongType"</span><span class="plain-syntax">, </span><span class="string-syntax">"GLK_EVENT_TY_Value2: Glk event phrase called for wrong event type."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Text</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax"> </span><span class="identifier-syntax">text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> == </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">CopyPV</span><span class="plain-syntax">(</span><span class="identifier-syntax">text</span><span class="plain-syntax">, </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">WindowBufferCopyToText</span><span class="plain-syntax">(</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax">, </span><span class="identifier-syntax">text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"EventWrongType"</span><span class="plain-syntax">, </span><span class="string-syntax">"GLK_EVENT_TY_Text: Glk event phrase called for wrong event type."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b><span class="extract"><span class="extract-syntax">GLK_EVENT_TY_From_Struct</span></span> takes a Glk event struct and conforms a Glk event
BV to it. This does not have to be a new Glk event - this function will usually
be used by <span class="extract"><span class="extract-syntax">glk_select</span></span>. It also handles a few event maintenance tasks.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_From_Struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax"> </span><span class="identifier-syntax">event_struct</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Erase this event</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">GLK_EVENT_TY_Destroy</span><span class="plain-syntax">(</span><span class="identifier-syntax">ev</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Check we have a known window</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> = </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;1);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> == </span><span class="identifier-syntax">evtype_CharInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_MouseInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_Hyperlink</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"EventUnknownWindow"</span><span class="plain-syntax">, </span><span class="string-syntax">"Event is on unknown Glk window."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Fill in the event</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">evtype</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;2;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;3;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Event maintenance</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">evtype</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">evtype_CharInput</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">INPUT_STATUS_NONE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">INPUT_STATUS_NONE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">evtype_MouseInput</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">requesting_mouse</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">evtype_Hyperlink</span><span class="plain-syntax">:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">requesting_hyperlink</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b><span class="extract"><span class="extract-syntax">GLK_EVENT_TY_To_Struct</span></span> then does the reverse, applying a Glk event BV back onto
the event struct.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_To_Struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax"> </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;0 = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;1 = (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax">).</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;1 = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;2 = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;3 = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b><span class="extract"><span class="extract-syntax">GLK_EVENT_TY_Handle_Instead</span></span> applies a glk event onto the current glk event, and
tells glk_select to re-run the glk event handling rules. It also ensures that
if there are any pending keyboard input requests they will be cancelled if the
new event is a keyboard event.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax"> --&gt; [ </span><span class="identifier-syntax">BLK_BVBITMAP_SBONLY</span><span class="plain-syntax">; </span><span class="identifier-syntax">GLK_EVENT_TY</span><span class="plain-syntax">; </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="constant-syntax">0</span><span class="plain-syntax">; ];</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GLK_EVENT_HANDLING_INACTIVE</span><span class="plain-syntax">   </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GLK_EVENT_HANDLING_ACTIVE</span><span class="plain-syntax">     </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">GLK_EVENT_HANDLING_REHANDLING</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">glk_event_handling_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GLK_EVENT_HANDLING_INACTIVE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">GLK_EVENT_TY_Handle_Instead</span><span class="plain-syntax"> </span><span class="identifier-syntax">ev</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">glk_event_handling_status</span><span class="plain-syntax"> == </span><span class="identifier-syntax">GLK_EVENT_HANDLING_INACTIVE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"EventHandledWhileInactive"</span><span class="plain-syntax">, </span><span class="string-syntax">"Cannot handle new event while not handling events."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">RulebookSucceeds</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">If the new event is text input, cancel a pending request</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> == </span><span class="identifier-syntax">evtype_CharInput</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> == </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_CHAR</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_CHAR_UNI</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_cancel_char_event</span><span class="plain-syntax">(</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> == </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_LINE</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_LINE_UNI</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_cancel_line_event</span><span class="plain-syntax">(</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">INPUT_STATUS_NONE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Update the current glk event</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">evtype</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">If the current event type is line input, update the buffer</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">evtype</span><span class="plain-syntax"> == </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WindowBufferSet</span><span class="plain-syntax">(</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">, </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TEXT_SF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ev</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE2_SF</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">RulebookSucceeds</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">glk_event_handling_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GLK_EVENT_HANDLING_REHANDLING</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>To handle events we intercept the <span class="extract"><span class="extract-syntax">glk_select</span></span> function. This allows us to handle
events early and consistently.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_select</span><span class="plain-syntax"> </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Call the real glk_select</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">192</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">GLK_EVENT_TY_From_Struct</span><span class="plain-syntax">(</span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">, </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Run the glk event handling rules (but disable rules debugging because it crashes if keyboard input events are pending)</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">debug_rules</span><span class="plain-syntax">; @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">say__p</span><span class="plain-syntax">; @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">say__pc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">debug_rules</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">; </span><span class="identifier-syntax">ClearParagraphing</span><span class="plain-syntax">(1);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">do</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">glk_event_handling_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GLK_EVENT_HANDLING_ACTIVE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">FollowRulebook</span><span class="plain-syntax">(</span><span class="identifier-syntax">GLK_EVENT_HANDLING_RB</span><span class="plain-syntax">, </span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">until</span><span class="plain-syntax"> (</span><span class="identifier-syntax">glk_event_handling_status</span><span class="plain-syntax"> == </span><span class="identifier-syntax">GLK_EVENT_HANDLING_ACTIVE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">glk_event_handling_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GLK_EVENT_HANDLING_INACTIVE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">pull</span><span class="plain-syntax"> </span><span class="identifier-syntax">say__pc</span><span class="plain-syntax">; @</span><span class="identifier-syntax">pull</span><span class="plain-syntax"> </span><span class="identifier-syntax">say__p</span><span class="plain-syntax">; @</span><span class="identifier-syntax">pull</span><span class="plain-syntax"> </span><span class="identifier-syntax">debug_rules</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">GLK_EVENT_TY_To_Struct</span><span class="plain-syntax">(</span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">, </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. Glk character event function keycodes.</b>These functions allow us to map the Glk function keycodes to our platform-agnostic unicode values.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">FunctionKeyCodesCount</span><span class="plain-syntax"> = </span><span class="constant-syntax">25</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">FunctionKeyCodes</span><span class="plain-syntax"> --&gt; </span><span class="constant-syntax">$ffffffe4</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffe5</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffe6</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffe7</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffe8</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$ffffffe9</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffea</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffeb</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffec</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffed</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffee</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffef</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$fffffff3</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff4</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff5</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff6</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff7</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff8</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff9</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$fffffffa</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffffb</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffffc</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffffd</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffffe</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffff</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">MappedFunctionKeyCodes</span><span class="plain-syntax"> --&gt; </span><span class="constant-syntax">$EF0C</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF0B</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF0A</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF09</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF08</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF07</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF06</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$EF05</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF04</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF03</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF02</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF01</span><span class="plain-syntax"> </span><span class="constant-syntax">$21F2</span><span class="plain-syntax"> </span><span class="constant-syntax">$21F1</span><span class="plain-syntax"> </span><span class="constant-syntax">$21DF</span><span class="plain-syntax"> </span><span class="constant-syntax">$21DE</span><span class="plain-syntax"> </span><span class="constant-syntax">$0009</span><span class="plain-syntax"> </span><span class="constant-syntax">$001B</span><span class="plain-syntax"> </span><span class="constant-syntax">$0008</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$000A</span><span class="plain-syntax"> </span><span class="constant-syntax">$2193</span><span class="plain-syntax"> </span><span class="constant-syntax">$2191</span><span class="plain-syntax"> </span><span class="constant-syntax">$2192</span><span class="plain-syntax"> </span><span class="constant-syntax">$2190</span><span class="plain-syntax"> </span><span class="constant-syntax">$FFFD</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">MapGlkKeyCodeToUnicode</span><span class="plain-syntax"> </span><span class="identifier-syntax">code</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">code</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        @</span><span class="identifier-syntax">binarysearch</span><span class="plain-syntax"> </span><span class="identifier-syntax">code</span><span class="plain-syntax"> </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax"> </span><span class="identifier-syntax">FunctionKeyCodes</span><span class="plain-syntax"> </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax"> </span><span class="identifier-syntax">FunctionKeyCodesCount</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> ~= -1) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">code</span><span class="plain-syntax"> = </span><span class="identifier-syntax">MappedFunctionKeyCodes</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">code</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="comment-syntax">In order to binary search, we need to sort them according to their mapped values, instead of their original Glk keycodes.</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">MappedFunctionKeyCodes_unmapping</span><span class="plain-syntax"> --&gt; </span><span class="constant-syntax">$0008</span><span class="plain-syntax"> </span><span class="constant-syntax">$0009</span><span class="plain-syntax"> </span><span class="constant-syntax">$000A</span><span class="plain-syntax"> </span><span class="constant-syntax">$001B</span><span class="plain-syntax"> </span><span class="constant-syntax">$2190</span><span class="plain-syntax"> </span><span class="constant-syntax">$2191</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$2192</span><span class="plain-syntax"> </span><span class="constant-syntax">$2193</span><span class="plain-syntax"> </span><span class="constant-syntax">$21DE</span><span class="plain-syntax"> </span><span class="constant-syntax">$21DF</span><span class="plain-syntax"> </span><span class="constant-syntax">$21F1</span><span class="plain-syntax"> </span><span class="constant-syntax">$21F2</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF01</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF02</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF03</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF04</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF05</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF06</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$EF07</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF08</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF09</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF0A</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF0B</span><span class="plain-syntax"> </span><span class="constant-syntax">$EF0C</span><span class="plain-syntax"> </span><span class="constant-syntax">$FFFD</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">FunctionKeyCodes_unmapping</span><span class="plain-syntax"> --&gt; </span><span class="constant-syntax">$fffffff9</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff7</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffffa</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff8</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$fffffffe</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffffc</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffffd</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffffb</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff6</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff5</span><span class="plain-syntax"> </span><span class="constant-syntax">$fffffff4</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$fffffff3</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffef</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffee</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffed</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffec</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffeb</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffea</span>
<span class="plain-syntax">    </span><span class="constant-syntax">$ffffffe9</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffe8</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffe7</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffe6</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffe5</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffe4</span><span class="plain-syntax"> </span><span class="constant-syntax">$ffffffff</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">MapUnicodeToGlkKeyCode</span><span class="plain-syntax"> </span><span class="identifier-syntax">code</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">binarysearch</span><span class="plain-syntax"> </span><span class="identifier-syntax">code</span><span class="plain-syntax"> </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax"> </span><span class="identifier-syntax">MappedFunctionKeyCodes_unmapping</span><span class="plain-syntax"> </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax"> </span><span class="identifier-syntax">FunctionKeyCodesCount</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span><span class="plain-syntax"> </span><span class="identifier-syntax">ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ix</span><span class="plain-syntax"> ~= -1) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">code</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FunctionKeyCodes_unmapping</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ix</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">code</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. Tracking input requests.</b>These replaced versions of the glk versions track which types of input have been
requested.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_cancel_char_event</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">211</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> + </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_cancel_hyperlink_event</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">259</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">requesting_hyperlink</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_cancel_line_event</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">event_struct</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax"> = </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">209</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> + </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">event_struct</span><span class="plain-syntax">--&gt;2;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_cancel_mouse_event</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">213</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">requesting_mouse</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_request_char_event</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">210</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_CHAR</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_request_char_event_uni</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">320</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_CHAR_UNI</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_request_hyperlink_event</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">258</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">requesting_hyperlink</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_request_line_event</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax"> </span><span class="identifier-syntax">maxlen</span><span class="plain-syntax"> </span><span class="identifier-syntax">initlen</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">initlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">maxlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">208</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_LINE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">buf</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_maxlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">maxlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_uni</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_request_line_event_uni</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax"> </span><span class="identifier-syntax">maxlen</span><span class="plain-syntax"> </span><span class="identifier-syntax">initlen</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">initlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">maxlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">321</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> = </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_LINE_UNI</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax"> = </span><span class="identifier-syntax">buf</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_maxlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">maxlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_uni</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">glk_request_mouse_event</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">push</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    @</span><span class="identifier-syntax">glk</span><span class="plain-syntax"> </span><span class="constant-syntax">212</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FindGlkWindowFromRefNum</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">win_obj</span><span class="plain-syntax">.</span><span class="identifier-syntax">requesting_mouse</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. Suspending and resuming text input.</b>These functions allow the author to suspend and then resume a window's text
input requests.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">SuspendTextInput</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_input_echoing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> == </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_CHAR</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_CHAR_UNI</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_cancel_char_event</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> == </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_LINE</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_LINE_UNI</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">glk_cancel_line_event</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="comment-syntax">Manually echo the command if required</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">BasicInformKit</span><span class="plain-syntax">`</span><span class="identifier-syntax">MANUAL_INPUT_ECHOING_CFGF</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">Cached_Glk_Gestalts</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">gestalt_LineInputEcho</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">no_input_echoing</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_set_style</span><span class="plain-syntax">(</span><span class="identifier-syntax">style_Input</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_put_buffer_uni</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_set_style</span><span class="plain-syntax">(</span><span class="identifier-syntax">style_Normal</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_put_char</span><span class="plain-syntax">(10); </span><span class="comment-syntax">newline</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">ResumeTextInput</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">INPUT_STATUS_SUSPENDED_CHAR</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_request_char_event</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">INPUT_STATUS_SUSPENDED_CHAR_UNI</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_request_char_event_uni</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">INPUT_STATUS_SUSPENDED_LINE</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_request_line_event</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_maxlen</span><span class="plain-syntax">, </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">INPUT_STATUS_SUSPENDED_LINE_UNI</span><span class="plain-syntax">:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">glk_request_line_event_uni</span><span class="plain-syntax">(</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">glk_ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_maxlen</span><span class="plain-syntax">, </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>These two phrases allow you to get and set the current line input of a window,
converting between Inform 7's texts, and the I6 buffers of the Glk API.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">WindowBufferCopyToText</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">txt</span><span class="plain-syntax"> </span><span class="identifier-syntax">buf_type</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_uni</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">buf_type</span><span class="plain-syntax"> = </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="comment-syntax">I don't remember why I was setting 0 here</span>
<span class="plain-syntax">            </span><span class="comment-syntax">in.line_input_buffer_addr--&gt;(win.line_input_buffer_curlen) = 0;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">buf_type</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="comment-syntax">in.line_input_buffer_addr-&gt;(win.line_input_buffer_curlen) = 0;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">BlkValueMassCopyFromArray</span><span class="plain-syntax">(</span><span class="identifier-syntax">txt</span><span class="plain-syntax">, </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax">, </span><span class="identifier-syntax">buf_type</span><span class="plain-syntax">, </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">txt</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">WindowBufferSet</span><span class="plain-syntax"> </span><span class="identifier-syntax">win</span><span class="plain-syntax"> </span><span class="identifier-syntax">txt</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">buf</span><span class="plain-syntax"> </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> </span><span class="identifier-syntax">cp</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax"> </span><span class="identifier-syntax">p</span><span class="plain-syntax"> </span><span class="identifier-syntax">uni</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (~~</span><span class="identifier-syntax">win</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"WindowIsNothing"</span><span class="plain-syntax">, </span><span class="string-syntax">"WindowCopyTextToBuffer: Cannot perform this Glk window operation on nothing."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"WindowHasNoBuffer"</span><span class="plain-syntax">, </span><span class="string-syntax">"Cannot set current line input of a window which has never requested line input."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">text_input_status</span><span class="plain-syntax"> == </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_LINE</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">INPUT_STATUS_ACTIVE_LINE_UNI</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"WindowHasActiveLineInput"</span><span class="plain-syntax">, </span><span class="string-syntax">"Cannot set current line input of a window with active line input."</span><span class="plain-syntax">, </span><span class="identifier-syntax">Architecture32KitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">buf</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_addr</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">uni</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_uni</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cp</span><span class="plain-syntax"> = </span><span class="identifier-syntax">txt</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">p</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TEXT_TY_Temporarily_Transmute</span><span class="plain-syntax">(</span><span class="identifier-syntax">txt</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">len</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BlkValueLBCapacity</span><span class="plain-syntax">(</span><span class="identifier-syntax">txt</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">len</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_maxlen</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">len</span><span class="plain-syntax"> = </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_maxlen</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">len</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BlkValueRead</span><span class="plain-syntax">(</span><span class="identifier-syntax">txt</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">uni</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">buf</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ch</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> &lt;= </span><span class="constant-syntax">$FF</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">buf</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ch</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">buf</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="character-syntax">'?'</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEXT_TY_Untransmute</span><span class="plain-syntax">(</span><span class="identifier-syntax">txt</span><span class="plain-syntax">, </span><span class="identifier-syntax">p</span><span class="plain-syntax">, </span><span class="identifier-syntax">cp</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">win</span><span class="plain-syntax">.</span><span class="identifier-syntax">line_input_buffer_curlen</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">If the current event is a line input event in this window, update event val 1</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_TYPE_SF</span><span class="plain-syntax"> == </span><span class="identifier-syntax">evtype_LineInput</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_WINDOW_SF</span><span class="plain-syntax"> == </span><span class="identifier-syntax">win</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">current_glk_event</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">GLK_EVENT_VALUE1_SF</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. Debugging verb.</b>This powers the GLKLIST command, when there's a command parser to read it.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">GlkDebuggingList</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_window_iterate</span><span class="plain-syntax">(0, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"Window "</span><span class="plain-syntax">, </span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="string-syntax">" ("</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0, </span><span class="string-syntax">"): "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_window_get_type</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"pair"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="constant-syntax">2</span><span class="plain-syntax">: </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"blank"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="constant-syntax">3</span><span class="plain-syntax">: </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"textbuffer"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="constant-syntax">4</span><span class="plain-syntax">: </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"textgrid"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="constant-syntax">5</span><span class="plain-syntax">: </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"graphics"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">default</span><span class="plain-syntax">: </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"unknown"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_window_get_parent</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">", parent is window "</span><span class="plain-syntax">, </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax">     </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">", no parent (root)"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_window_get_stream</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">", stream "</span><span class="plain-syntax">, </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_window_get_echo_stream</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val</span><span class="plain-syntax">) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">", echo stream "</span><span class="plain-syntax">, </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_window_iterate</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_stream_iterate</span><span class="plain-syntax">(0, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"Stream "</span><span class="plain-syntax">, </span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="string-syntax">" ("</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0, </span><span class="string-syntax">")^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_stream_iterate</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_fileref_iterate</span><span class="plain-syntax">(0, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"Fileref "</span><span class="plain-syntax">, </span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="string-syntax">" ("</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0, </span><span class="string-syntax">")^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_fileref_iterate</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">glk_gestalt</span><span class="plain-syntax">(</span><span class="identifier-syntax">gestalt_Sound</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_schannel_iterate</span><span class="plain-syntax">(0, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">id</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"Soundchannel "</span><span class="plain-syntax">, </span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="string-syntax">" ("</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">--&gt;0, </span><span class="string-syntax">")^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">glk_schannel_iterate</span><span class="plain-syntax">(</span><span class="identifier-syntax">id</span><span class="plain-syntax">, </span><span class="identifier-syntax">gg_arguments</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="intm.html">&#10094;</a></li><li class="progresssection"><a href="cptm.html">cptm</a></li><li class="progresssection"><a href="intm.html">intm</a></li><li class="progresscurrent">gltm</li><li class="progresssection"><a href="sttm.html">sttm</a></li><li class="progresssection"><a href="sttm2.html">sttm2</a></li><li class="progresssection"><a href="mttm.html">mttm</a></li><li class="progresssection"><a href="cst.html">cst</a></li><li class="progresssection"><a href="iot.html">iot</a></li><li class="progresssection"><a href="fiot.html">fiot</a></li><li class="progresssection"><a href="vntm.html">vntm</a></li><li class="progresssection"><a href="vnt.html">vnt</a></li><li class="progressnext"><a href="sttm.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

